from pages.base_page import BasePage
from time import sleep


class NewestPage(BasePage):
    level1_comment_input = '//*[@resource-id="cool.dingstock.mobile:id/edit_hint_tv"]'
    level1_comment_input1 = '//*[@resource-id="cool.dingstock.mobile:id/comment_et"]'
    level1_comment_send = '//*[@resource-id="cool.dingstock.mobile:id/send_btn"]'
    trend_back = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_left_icon"]'
    first_trend_comment_num = '//*[@resource-id="cool.dingstock.mobile:id/tv_post_comment"]'
    first_trend_like = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[3]/android.widget.ImageView[1]'
    first_trend_like_num = '//*[@text="点赞"]'
    after_like_num = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.view.ViewGroup[3]/android.widget.TextView[1]'
    after_cancel_like_num = '//*[@text="点赞"]'
    collect_first_trend = '//*[@resource-id="cool.dingstock.mobile:id/tv_collection"]'
    first_trend_content = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_content_txt"]'
    third_trend_menu = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[3]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/androidx.appcompat.widget.LinearLayoutCompat[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]'
    third_trend_report = '//*[@resource-id="cool.dingstock.mobile:id/rv_post_action"]/android.widget.LinearLayout[3]'
    detail_comment_num = '//*[@resource-id="cool.dingstock.mobile:id/tv_post_comment"]'
    first_trend_1_comment = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]'
    level2_comment_input = '//*[@resource-id="cool.dingstock.mobile:id/comment_et"]'
    first_image_xpath = '//*[@resource-id="cool.dingstock.mobile:id/mRecyclerView"]/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.FrameLayout[1]/android.widget.CheckBox[1]'
    # a = '//*[@resource-id="cool.dingstock.mobile:id/mRecyclerView"]/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]'
    next_step_xpath = '//*[@resource-id="cool.dingstock.mobile:id/tv_rightBtn"]'
    add_comment_image = '//*[@resource-id="cool.dingstock.mobile:id/select_pic_iv"]'
    level2_comment_send = '//*[@resource-id="cool.dingstock.mobile:id/send_btn"]'
    third_trend_detail = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[3]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]'
    second_trend_first_comment = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]'
    comment_copy = '//*[@resource-id="cool.dingstock.mobile:id/rv_menu_action"]/android.widget.LinearLayout[1]'
    paste_button_xpath = '//*[@text="粘贴"]'
    first_trend_menu = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/androidx.appcompat.widget.LinearLayoutCompat[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.ImageView[1]'
    first_trend_delete = '//*[@resource-id="cool.dingstock.mobile:id/rv_post_action"]'
    delete_confirm = '//*[@resource-id="cool.dingstock.mobile:id/confirm_tv"]'
    first_trend_detail = '//*[@resource-id="cool.dingstock.mobile:id/home_fragment_second_rv"]/android.view.ViewGroup[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]'
    second_trend_detail = '//*[@text="qwe"]'
    first_comment_like = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]'
    first_comment_like_num = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_comment_like_txt"]'
    first_comment_body = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[1]'
    first_comment_delete = '//*[@resource-id="cool.dingstock.mobile:id/rv_menu_action"]'
    comment_report = '//*[@resource-id="cool.dingstock.mobile:id/rv_menu_action"]/android.widget.LinearLayout[2]'
    second_trend_comment_button = '//*[@resource-id="cool.dingstock.mobile:id/iv_post_comment"]'
    comment_look_image_button = '//*[@resource-id="cool.dingstock.mobile:id/circle_view_dynamic_subcomment_better_link_txt"]'
    image_download = '//*[@resource-id="cool.dingstock.mobile:id/img_download"]'
    level2_comment_detail = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_comment_subContent_recycler"]'
    level2_comment_like = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.ImageView[1]'
    level2_comment_like_num = '//*[@resource-id="cool.dingstock.mobile:id/circle_item_dynamic_comment_like_txt"]'
    second_comment_detail = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/androidx.recyclerview.widget.RecyclerView[1]'
    second_level2_comment = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[2]'
    first_level2_comment = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_comment_common_rv"]/android.widget.LinearLayout[2]'
    close_comment_detail_button = '//*[@resource-id="cool.dingstock.mobile:id/iv_close"]'
    all_album = '//*[@resource-id="cool.dingstock.mobile:id/tv_title"]'
    test_album = '//*[@text="tesr"]'

    def click_first_trend(self):
        """进入第一条动态的详情"""
        self.click_xpath(self.first_trend_detail)

    def input_comment(self,text):
        """输入评论内容"""
        self.click_xpath(self.level1_comment_input)
        self.set_xpath_text(self.level1_comment_input1,text)


    def click_send_comment(self):
        """点击发布评论"""
        self.click_xpath(self.level1_comment_send)

    def get_comment_num(self):
        """获取评论数量"""
        return self.get_xpath_text(self.first_trend_comment_num)

    def get_detail_comment_num(self):
        """获取第一条动态详情页的评论数量"""
        return self.get_xpath_text(self.detail_comment_num)

    def trend_detail_back(self):
        """动态详情页返回到首页"""
        self.click_xpath(self.trend_back)

    def like_first_trend(self):
        """点赞第一个动态"""
        self.click_xpath(self.first_trend_like)

    def cancel_like_first_trend(self):
        """取消点赞第一个动态"""
        self.click_xpath(self.first_trend_like)

    def get_origin_like_num(self):
        """获取第一个动态点赞数"""
        return self.get_xpath_text(self.first_trend_like_num)

    def get_after_like_num(self):
        """获取点赞后数量"""
        return self.get_xpath_text(self.after_like_num)

    def get_after_cancel_like_num(self):
        """获取取消点赞后数量"""
        return self.get_xpath_text(self.after_cancel_like_num)

    def first_trend_collect(self):
        """收藏第一个动态"""
        self.click_xpath(self.collect_first_trend)

    def first_trend_collect_cancel(self):
        """取消收藏第一个动态"""
        self.click_xpath(self.collect_first_trend)

    def get_first_trend_content(self):
        """检查是否收藏成功"""
        return self.get_xpath_text(self.first_trend_content)

    def report_third_trend(self):
        """举报第三条动态"""
        self.click_xpath(self.third_trend_menu)
        self.click_xpath(self.third_trend_report)

    def send_level2_comment(self, text):
        """评论第一条一级评论，携带图片"""
        self.click_xpath(self.first_trend_1_comment)
        self.set_xpath_text(self.level2_comment_input, text)
        self.click_xpath(self.level2_comment_send)

    def into_third_trend(self):
        """进入第三条动态详情页"""
        self.click_xpath(self.third_trend_detail)

    def copy_first_comment(self):
        """长按第一条评论,点击复制"""
        self.long_press(self.second_trend_first_comment)
        self.click_xpath(self.comment_copy)

    def paste_copy_content(self):
        """点击评论输入框，粘贴复制内容"""
        self.click_xpath(self.second_trend_comment_button)
        self.long_press(self.level1_comment_input1)
        self.click_xpath(self.paste_button_xpath)

    def get_comment_input_content(self):
        """获取评论输入框的文本内容"""
        return self.get_xpath_text(self.level1_comment_input1)

    def delete_first_trend(self):
        """删除刚刚发布的第一条动态"""
        self.click_xpath(self.first_trend_menu)
        self.click_xpath(self.first_trend_delete)
        self.click_xpath(self.delete_confirm)

    def into_second_trend(self):
        """进入第二条动态详情页"""
        self.click_xpath(self.second_trend_detail)

    def like_level1_comment(self):
        """点赞一级评论"""
        self.click_xpath(self.first_comment_like)

    def cancel_like_level1_comment(self):
        """取消点赞"""
        self.click_xpath(self.first_comment_like)

    def is_like_num_exist(self):
        """判断点赞数量是否显示"""
        return self.is_xpath_exist(self.first_comment_like_num)

    def delete_first_comment(self):
        """删除第一条动态评论"""
        self.long_press(self.first_comment_body)
        sleep(1)
        self.click_xpath(self.first_comment_delete)
        sleep(1)
        self.click_xpath(self.delete_confirm)

    def report_first_comment(self):
        """举报动态第一条评论"""
        self.long_press(self.second_trend_first_comment)
        self.click_xpath(self.comment_report)

    def look_comment_image(self):
        """查看二级评论图片"""
        self.click_xpath(self.comment_look_image_button)

    def is_look_image_exist(self):
        """查看图片按钮是否存在"""
        return self.is_xpath_exist(self.comment_look_image_button)

    def is_download_image_exist(self):
        """下载图片按钮是否存在"""
        return self.is_xpath_exist(self.image_download)

    def into_level2_comment(self):
        """查看二级评论详情"""
        self.click_xpath(self.level2_comment_detail)

    def like_level2_comment(self):
        """二级评论点赞"""
        self.click_xpath(self.level2_comment_like)

    def is_level2_comment_like_exist(self):
        """二级评论点赞数元素是否存在"""
        return self.is_xpath_exist(self.level2_comment_like_num)

    def copy_level2_comment(self):
        """二级评论复制"""
        self.click_xpath(self.second_comment_detail)
        self.long_press(self.second_level2_comment)
        self.click_xpath(self.comment_copy)

    def report_level2_comment(self):
        """举报二级评论"""
        self.click_xpath(self.second_comment_detail)
        self.long_press(self.second_level2_comment)
        self.click_xpath(self.comment_report)

    def delete_level2_comment(self):
        """删除二级评论"""
        self.long_press(self.first_level2_comment)
        self.click_xpath(self.first_comment_delete)
        self.click_xpath(self.delete_confirm)
        self.click_xpath(self.close_comment_detail_button)